package com.letian.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.record.domain.RecordHaircut;
import com.letian.record.service.IRecordHaircutService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 记录发型Controller
 * 
 * @author bmz
 * @date 2023-05-15
 */
@RestController
@RequestMapping("/record/haircut")
public class RecordHaircutController extends BaseController
{
    @Autowired
    private IRecordHaircutService recordHaircutService;

    /**
     * 查询记录发型列表
     */
    @PreAuthorize("@ss.hasPermi('record:haircut:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordHaircut recordHaircut)
    {
        startPage();
        List<RecordHaircut> list = recordHaircutService.selectRecordHaircutList(recordHaircut);
        return getDataTable(list);
    }

    /**
     * 导出记录发型列表
     */
    @PreAuthorize("@ss.hasPermi('record:haircut:export')")
    @Log(title = "记录发型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordHaircut recordHaircut)
    {
        List<RecordHaircut> list = recordHaircutService.selectRecordHaircutList(recordHaircut);
        ExcelUtil<RecordHaircut> util = new ExcelUtil<RecordHaircut>(RecordHaircut.class);
        util.exportExcel(response, list, "记录发型数据");
    }

    /**
     * 获取记录发型详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:haircut:query')")
    @GetMapping(value = "/{haircutId}")
    public AjaxResult getInfo(@PathVariable("haircutId") Long haircutId)
    {
        return success(recordHaircutService.selectRecordHaircutByHaircutId(haircutId));
    }

    /**
     * 新增记录发型
     */
    @PreAuthorize("@ss.hasPermi('record:haircut:add')")
    @Log(title = "记录发型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordHaircut recordHaircut)
    {
        recordHaircut.setCreateBy(getUsername());
        return toAjax(recordHaircutService.insertRecordHaircut(recordHaircut));
    }

    /**
     * 修改记录发型
     */
    @PreAuthorize("@ss.hasPermi('record:haircut:edit')")
    @Log(title = "记录发型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordHaircut recordHaircut)
    {
        recordHaircut.setUpdateBy(getUsername());
        Long count = recordHaircut.getUpdateCount() == null ? 1 : recordHaircut.getUpdateCount() + 1;
        recordHaircut.setUpdateCount(count);
        return toAjax(recordHaircutService.updateRecordHaircut(recordHaircut));
    }

    /**
     * 删除记录发型
     */
    @PreAuthorize("@ss.hasPermi('record:haircut:remove')")
    @Log(title = "记录发型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{haircutIds}")
    public AjaxResult remove(@PathVariable Long[] haircutIds)
    {
        return toAjax(recordHaircutService.deleteRecordHaircutByHaircutIds(haircutIds));
    }
}
